#include <cstdio>
int kase;
char c;
int n,m;

int f(int s,int e)
{
    int sum=1;
    for(int i=s;i<=e;i++)
        sum*=i;
    return sum;
}

void ans()
{
    if ( c == 'A')
    {
        printf("%d\n",f(n-m+1,n));
    }
    if ( c == 'C' )
    {
        printf("%d\n",f(n-m+1,n)/f(1,m));
    }
}

int main()
{
    scanf("%d",&kase);
    while ( kase-- )
    {
        getchar();          //!!!!!!!!!!!!!
        scanf("%c%d%d",&c,&n,&m);
        ans();
    }
    return 0;
}
